﻿/**
作者：常亮
时间：209-11-19
功能：实现用户增加
**/
var Obj = new Object();
var UploadActionPath = SBasePath + "/action/upload/";
var ContactUsImageArray = new Array();
var ImageArr = new Array('.jpg', '.gif', '.png', '.bmp'); //形象图片类型
var UploadType = 1; //1:缩略图2:原图
var _mDebug=false; //用于调试显示上传显示部分
var ModelID, ModelParentID;
function ShowMain() {
    ModelID = request("ModelId");
    ModelParentID = request("ModelParentId");
    ShowContent();
}

var FormSubmit = function() {
    if (CheckAddForm()) {
        $("bc").disabled = "disabled";
        document.getElementById("shenhe").value = document.getElementById("sh").value;
        var url = encodeURI(SBasePath + '/action/Contents/RelContent.aspx');
        var myAjax = new Ajax.Request(url, { method: 'post', parameters: Form.serialize("formsubmit"), onComplete: sFormSubmit, onFailure: fFormSubmit });
    }
};

var sFormSubmit = function(o) {
    var root = o.responseXML.documentElement;
    var flag = GetXmlData(root, "Value");
    if (flag == "true") {
        MsgDlgLocal('添加成功！');
    }
    else {
        $("bc").disabled = "";
    }
};

var fFormSubmit = function(o) {
    $("bc").disabled = "";

};

var CheckAddForm = function() {
    var fobj = $("formsubmit");


    if (document.getElementById("name").value == "") {
        MsgDlg("标题名称不能为空!");
        fobj.name.focus();
        return false;
    }

    if (Trim(fobj.CommentContent.value) == "" && Trim(fobj.lj.value) == "") {

        MsgDlg("发布内容和链接不能同时为空!");
        return false;

    } else if (Trim(fobj.CommentContent.value) != "" && Trim(fobj.lj.value) != "") {

        MsgDlg("发布内容和链接不能同时有内容!");
        fobj.CommentContent.value = "";
        fobj.lj.value = "";
        return false;

    } else if (Trim(fobj.CommentContent.value) == "" && Trim(fobj.lj.value) != "") {

        var booltf = checkeURL(fobj.lj.value);

        if (booltf == false) {
            MsgDlg("请输入正确的网址,必须以http://开头！");
            fobj.lj.value = "";
            fobj.lj.focus();
            return false;
        }
    }
    return true;

};
var shenhe;
function nrsh() {
    shenhe = document.getElementById("sh").value;
}

function ShowContent() {
 var str = "";
 str+= '<form id="formsubmit">';
 str += '<input type="hidden" name="ShrinUrl" id="ShrinUrl" value="">';
 str += '<input type="hidden" name="ModelID" id="ModelID" value="' + ModelID + '">'
 str += '<input type="hidden" name="ModelParentID" id="ModelParentID" value="' + ModelParentID + '">';
 str += '<input type="hidden" name="shenhe" id="shenhe" value="' +shenhe+ '">';

 str+= '<table width="100%" height="100%" border="0" align="center" cellpadding="0" cellspacing="0">';
 str+= '<OBJECT id="dlgHelper" CLASSID="clsid:3050f819-98b5-11cf-bb82-00aa00bdce0b" width="0px" height="0px"></OBJECT>';
 str+=' <tr>';
 str+='   <td height="30"><table width="100%" border="0" cellspacing="0" cellpadding="0">';
 str+='     <tr>';
 str+='       <td width="15" height="30" class="tab03"></td>';
 str+='       <td class="tab05"><div class="title1"  style="padding-top:2px"><img src="../../img/1.gif" height="20" width="19"/>内容发布</div></td>';
 str+='       <td width="14" class="tab07"></td>';
 str+='     </tr>';
 str+='   </table></td>';
 str+=' </tr>';
 str+=' <tr>';
 str+='   <td valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0">';
 str+='     <tr>';
 str+='       <td width="9" class="tab12"></td>';
 str+='       <td bgcolor="#f3ffe3" valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0">';
 str+=' <tr>';
 str+='   <td class="k_hui" valign="top"><table width="100%" border="0" cellspacing="2" cellpadding="0" align="center" class="bg_w">';
 str+=' <tr class="bg_g">';
 str+='   <td width="10%" rowspan="2" class="zw"  align="center">标题信息</td>';
 str+='   <td width="90%" height="30" style="padding-left:3px"><table cellpadding="0" cellspacing="0" border="0" class="zw" >';
 str+='		<tr>';
 str += '	  <td width="70">';
 str += '        <select name="select" size="1" style="width:120px; height:20px" class="select" onChange="setFace(this, document.all.name)"  title="设置文字的字体" class="k_green">';
 str += '	                        <OPTION VALUE="">字体</OPTION>';
 str += '							<OPTION VALUE="宋体">宋体</OPTION>';
 str += '							<OPTION VALUE="新宋体">新宋体</OPTION>';
str += '							<OPTION VALUE="黑体">黑体</OPTION>';
str += '							<OPTION VALUE="仿宋_GB2312">仿宋_GB2312</OPTION>';
str += '							<OPTION VALUE="楷体_GB2312">楷体_GB2312</OPTION>';
str += '							<OPTION VALUE="隶书">隶书</OPTION>';
str += '							<OPTION VALUE="华文彩云">华文彩云</OPTION>';
str += '							<OPTION VALUE="华文细黑">华文细黑</OPTION>';
str += '							<OPTION VALUE="华文新魏">华文新魏</OPTION>';
str += '							<OPTION VALUE="华文行楷">华文行楷</OPTION>';
str += '							<OPTION VALUE="华文中宋">华文中宋</OPTION>';
str += '							<OPTION VALUE="幼圆">幼圆</OPTION>';
str += '							<OPTION VALUE="方正舒体">方正舒体</OPTION>';
str += '							<OPTION VALUE="方正姚体">方正姚体</OPTION>';
str += '							<OPTION VALUE="Arial">Arial</OPTION>';
str += '							<OPTION VALUE="Arial Black">Arial Black</OPTION>';
str += '							<OPTION VALUE="Arial Narrow">Arial Narrow</OPTION>';
str += '							<OPTION VALUE="Batang">Batang</OPTION>';
str += '							<OPTION VALUE="Comic Sans MS">Comic Sans MS</OPTION>';
str += '							<OPTION VALUE="Courier New">Courier New</OPTION>';
str += '							<OPTION VALUE="Tahoma">Tahoma</OPTION>';
str += '							<OPTION VALUE="Times New Roman">Times New Roman</OPTION>';
str += '							<OPTION VALUE="Verdana">Verdana</OPTION>';
str += '      </select>';
str += '   </td>';

str += ' <td width="22" style="padding-left:5px">';
str += '     <select name="select"  onChange="setSize(this, document.all.name)"  title="设置文字的字号" size="1" style="width:50px; height:20px " class="k_green">';
str+='	                    <option>字号</option>';
str+='                      <OPTION VALUE="1">1</OPTION>';
str+='						<OPTION VALUE="2">2</OPTION>';
str+='						<OPTION VALUE="3">3</OPTION>';
str+='						<OPTION VALUE="4">4</OPTION>';
str+='						<OPTION VALUE="5">5</OPTION>';
str+='						<OPTION VALUE="6">6</OPTION>';
str+='						<OPTION VALUE="7">7</OPTION>';
str+='						<OPTION VALUE="8">8</OPTION>';
str+='						<OPTION VALUE="9">9</OPTION>';
str+='						<OPTION VALUE="10">10</OPTION>';
str+='						<OPTION VALUE="12">12</OPTION>';
str+='						<OPTION VALUE="14">14</OPTION>';
str+='						<OPTION VALUE="16">16</OPTION>';
str+='						<OPTION VALUE="18">18</OPTION>';
str+='						<OPTION VALUE="20">20</OPTION>';
str+='						<OPTION VALUE="24">24</OPTION>';
str+='					    <OPTION VALUE="28">28</OPTION>';
str+='						<OPTION VALUE="32">32</OPTION>';
str+='						<OPTION VALUE="64">64</OPTION>';
str += '      </select>';
str += '</td>';

	str += '<td>&nbsp;&nbsp;</td>';
	str += '					<TD  class="td01">';
	str += '					<img src="../../img/button.textcolor.gif" border="0" onClick="javascript:showColor(document.all.name);return(false);" title="设置文字的颜色" class="img0"/>';
	str += '					</TD>';
	str += '					<TD width="21" class="td01">';
	str += '					<img src="../../img/button.bgcolor.gif" border="0" onClick="javascript:showBgColor(document.all.name);return(false);" title="设置文字的背景颜色" class="img0"/>';
	str += '					</TD>';
	str += '					<TD width="21" class="td01">';
	str += '					<img src="../../img/button.bold.gif" border="0" onClick="javascript:setProperty3(document.all.name,\'B\');return(false);" title="设置文字为粗体" class="img0"/>';
	str += '					</TD>';
	str += '					<TD width="21" class="td01">';
	str += '					<img src="../../img/button.italic.gif" border="0" onClick="javascript:setProperty3(document.all.name,\'I\');return(false);" title="设置文字为斜体" class="img0"/>';
	str += '					</TD>';
	str += '					<TD width="21" class="td01">';
	str += '					<img src="../../img/button.underline.gif" border="0" onClick="javascript:setProperty3(document.all.name,\'U\');return(false);" title="设置文字下划线" class="img0"/>';
	str += '					</TD>';
	str += '					<TD width="21" class="td01">';
	str += '					<img src="../../img/button.strikethrough.gif" border="0" onClick="javascript:setProperty3(document.all.name,\'STRIKE\');return(false);" title="设置文字删除线" class="img0"/>';
	str += '					</TD>';
str+='		</tr></table></td>';
str+='  </tr>';
str+='  <tr class="bg_g">';
str+='    <td width="90%"  class="zw" style="padding-left:5px">';
str+='      <textarea name="name" id="name" cols="50" rows="11" style="height:50px; width:100%; border:solid 1px #cadcb2;"></textarea>';
str+='   </td>';
str += '  </tr>';

str += '  <tr class="bg_g">';
str += '    <td width="10%" height="30" class="zw" align="center">内容审核</td>';
str += '    <td width="90%" class="zw" style="padding-left:3px">';
str += '     <select name="sh" id="sh"  onChange="nrsh()"  title="内容审核" size="1" style="width:100px; height:20px " class="k_green">';
str += '                    <OPTION VALUE="1">通过</OPTION>';
str += '					<OPTION VALUE="0">未通过</OPTION>';

str += '      </select>';
str += '    </td>';
str += '  </tr>';


str += '  <tr class="bg_g">';
str += '    <td width="10%" height="30" class="zw" align="center">标题链接</td>';
str += '    <td width="90%" class="zw" style="padding-left:3px">';
str += '    <input type="text" name="lj" id="lj" style="width:50%; border:solid 1px #cadcb2;"/><font color="red">【必须加 http://】</font>';
str += '    </td>';
str += '  </tr>';

str += '  <tr class="bg_g">';
str += '    <td width="10%" height="30" class="zw" align="center">发布时间</td>';
str += '    <td width="90%" class="zw" style="padding-left:3px">';
str += '    <input type="text" name="fbtime" id="fbtime" style="width:50%; border:solid 1px #cadcb2;"/><font color="red">【时间格式：2010-3-1】</font>';
str += '    </td>';
str += '  </tr>';

str+='  <tr class="bg_g">';
str+='    <td width="10%" height="30" class="zw" align="center">信息内容</td>';
str += '    <td width="90%" class="zw" style="padding-left:3px">';


str += '	                 <div id="_CommentFCKeditor" style="display: none">';
str += '                    <textarea id="_CommentDataFCKeditor" cols="90" rows="6" style="width: 95%"></textarea>';
str += '	                 </div>';
str += '        <IFRAME src="eWebEditor/ewebeditor.htm?id=_CommentDataFCKeditor&style=coolblue"  frameborder="0" scrolling="no" width="500" height="350" style="width: 543px"></IFRAME>';

//str += '                  <div id="_CommentTextarea">';
//str += '	                 <textarea id="_CommentDataTextarea" name="CommentContent"  cols="90" rows="6" style="width: 95%"></textarea>';
//str += '	                 </div>';
//str += '	                 <div id="_CommentFCKeditor" style="display: none">';
//str += '                    <textarea id="_CommentDataFCKeditor" cols="90" rows="6" style="width: 95%"></textarea>';
//str += '	                 </div>';
str+='    </td>';
str += '  </tr>';
str += '</form>';
str += '  <tr class="bg_g">';
str += '    <td width="10%" height="15" class="zw" align="center">图片上传</td>';
str += '    <td width="90%" style="padding-left:3px">';
str += '                <form name="myform" id="myform" action="' + UploadActionPath + 'UploadCommResult.aspx"; method="post" enctype="multipart/form-data" target="targethidenfram">';
str += '                <input type="file" value="" name="file1" id="file1" class="input2">';
str += '                <input onclick="StartUpload(\'myform\',\'1\');" type="button" name="SubmitButton" id="SubmitButton"   style="height:23"  value="上传">';
str += '                <div id="progressout"></div>';
str += '                <div id="ShrinImageDiv"></div>';
str += '                 </form>';
str += '    </td>';
str += '  </tr>';
str += '  <tr class="bg_g">';
str += '    <td  height="15"  colspan="2" class="zw" align="center">';
str += '                <input type="button"  value="保存" width="100px" id="bc" onclick="PrepareSave(\'Comment\');FormSubmit();"   />';
str += '                <input type="button"  value="返回" id="back" onclick="Back()" class="m_button" />';

str += '  </td></tr>';

str+='</table></td>';
str+='  </tr>';
str+='</table></td>';
str += '        <td width="9" class="tab16">';

str+='      </td></tr>';
str+='    </table></td>';
str += '  </tr>';

str+='  <tr>';
str+='    <td height="29"><table width="100%" border="0" cellspacing="0" cellpadding="0">';
str+='      <tr>';
str+='        <td width="15" height="29" class="tab20"></td>';
str+='        <td  class="tab21">&nbsp;</td>';
str += '        <td width="14" class="tab22"></td>';
str+='      </tr>';
str+='    </table></td>';
str+='  </tr>';
str += '</table>';



if (_mDebug) {
    str += '  <iframe id="targethidenfram" name="targethidenfram" frameborder="0" height="200" width="400" visible="false"></iframe>';
}
else {
    str += '  <iframe id="targethidenfram" name="targethidenfram" frameborder="0" height="0" width="0" visible="false"></iframe>';
}

$("Contents").innerHTML = str;
//editor("Comment");

}

//生成副文本编辑器
//参数name是控件Textarea的名称的前面部分主要用于下面组成完整的名称
function editor(name)
{
    var oEditor ;
    if ( typeof( FCKeditorAPI ) != 'undefined' )
	    oEditor = FCKeditorAPI.GetInstance( '_'+name+'DataFCKeditor' ) ;       
    var eTextareaDiv	= document.getElementById( '_'+name+'Textarea' ) ;
    var eFCKeditorDiv	= document.getElementById( '_'+name+'FCKeditor' ) ;

    if ( eTextareaDiv.style.display != 'none' )
    {
	    if ( !oEditor )
	    {
		    CreateEditor(name) ;
	    }
	    else
	    {
		    CreateEditor(name) ;
	    }

	    eTextareaDiv.style.display = 'none' ;
	    eFCKeditorDiv.style.display = '' ;
	    if ( oEditor && !document.all )
	    {
		    if ( oEditor.EditMode == FCK_EDITMODE_WYSIWYG )
			    oEditor.MakeEditable() ;
	    }
    }
    else
    {
	    document.getElementById('_'+name+'DataTextarea').value = oEditor.GetXHTML() ;
	    eTextareaDiv.style.display = '' ;
	    eFCKeditorDiv.style.display = 'none' ;
    }
}

function CreateEditor(name)
{	
	document.getElementById('_'+name+'DataFCKeditor').value = document.getElementById('_'+name+'DataTextarea').value ;
	var sBasePath = document.location.pathname.substring(0,document.location.pathname.lastIndexOf('AdminManage')) ;
	var oFCKeditor = new FCKeditor( '_'+name+'DataFCKeditor' ) ;
	oFCKeditor.BasePath = SBasePath+"/";
	oFCKeditor.Width = '700' ;
	oFCKeditor.Height = '400' ;
	oFCKeditor.ReplaceTextarea() ;
}

function FCKeditor_OnComplete( editorInstance )
{
}

function PrepareSave(name) //进行保存
{
	if (document.getElementById( '_'+name+'Textarea' ).style.display == 'none' )
	{
		var oEditor = FCKeditorAPI.GetInstance( '_'+name+'DataFCKeditor' ) ;
		document.getElementById( '_'+name+'DataTextarea' ).value = oEditor.GetXHTML() ;
    }
}



/*-------------------------------------------以下关于上传-------------------------------------------------*/
var progressWindow;
function StartUpload(formObj, Type)//开始上传
{
    UploadType = Type;
    if (chkGroupImageFileValid()) {
        if (typeof (formObj) == "string")
            formObj = document.getElementById(formObj);
        //Show Cancel button
        var CancelButton = document.getElementById("CancelButton");
        if (CancelButton && PowUploadCanCancel())
            CancelButton.style.visibility = "visible";
        
        var uniqueID = Math.floor(Math.random() * 10000000) + (new Date()).getTime() % 1000000000;
        progressWindow = ShowProgressInFrame(uniqueID, UploadActionPath + 'Progress.aspx', 400, 200); //显示进度条	
    
        thePos = formObj.action.indexOf("UploadID");
        //Cut earlier added UploadID.
        if (thePos >= 1)
            formObj.action = formObj.action.substring(0, thePos - 1);
        if (formObj.action.indexOf("?") == -1)
            formObj.action += '?UploadID=' + uniqueID
        else
            formObj.action += '&UploadID=' + uniqueID;
        formObj.submit();
        return true;
    }
}

//Function ShowProgressInNewWindow() to show progress bar in new window.
function ShowProgressInFrame(uniqueID, URL, width, height) {
    var l = (screen.width - width) / 2;
    var t = (screen.height - height) / 2;
    //	var winParams = 'toolbar=no,scrollbars=no,location=no,status=no,menubar=no,resizable=yes';
    //	winParams += ',width=' + width + ',height=' + height + ',left=' + l + ',top=' + t;
    var fullURL = URL;
    thePos = fullURL.indexOf("UploadID");
    //Cut earlier added UploadID.
    if (thePos >= 1)
        fullURL = fullURL.substring(0, thePos - 1);
    if (URL.indexOf("?") == -1)
        fullURL += '?UploadID=' + uniqueID;
    else
        fullURL += '&UploadID=' + uniqueID;
    $("progressout").innerHTML = '<iframe id="progressframe" name="' + uniqueID + '" frameborder="0" height="' + height + '" width="' + width + '" visible="true" src="' + fullURL + '" SCROLLING="no"></iframe>';
    //var newProgressWindow = window.open(fullURL, uniqueID, winParams);
    var newProgressWindow = $("progressframe");
    return newProgressWindow;
}

//上传成功后的回调函数
function UploadCommplete(fobjs) {

    var str = "";
    var filename = "";
    if (fobjs != null) {
        for (var i = 0; i < fobjs.length; i++) {
            str += fobjs[i].FileName + "<br>";
            if (fobjs[i].FileName != "") {
                filename = fobjs[i].FileName;
            }
        }
    }

    $("progressout").style.display = "none";
    if (UploadType == 1) {
        //  $("ShrinImageDiv").innerHTML = '<img src="/web' + filename + '" width="300" height="300" />';
        $("ShrinImageDiv").innerHTML = '<a href="/web' + filename + '" target="_blank" >上传成功</a>';
        $("ShrinUrl").value = filename;
    }
    else {
        ContactUsImageArray[ContactUsImageArray.length++] = filename;
        ShowContactUsImage(ContactUsImageArray);
    }


}

//检查形象图片的合法性
function chkGroupImageFileValid() {
    var objs = null;
    if (UploadType == 1) {

        objs = $("file1");
    }
    else {
        objs = $("file2");
    }

    if (objs.value == "") {
        MsgDlg("您还没有选择任何文件!");
        return false;
    }
    else {
        var name = objs.value;
        name = name.substring(name.lastIndexOf('.'));
        for (var i = 0; i < ImageArr.length; i++) {
            if (name.toLowerCase() == ImageArr[i]) {
                return true;
            }
        }
        MsgDlg("您所选择的文件类型不对!");
        return false;
    }
}


/*-------------------------------------------以下关于上传-------------------------------------------------*/